package com.sky.controller.admin;

import com.sky.dto.OtherProductDTO;
import com.sky.dto.OtherProductPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OtherProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/otherProduct")  // 添加基础路径
@Api(tags = "其他产品相关接口")
@Slf4j
public class OtherProductController {

    @Autowired
    private OtherProductService otherProductService;

    @PostMapping
    @ApiOperation("新增其他产品")
    public Result save(@RequestBody OtherProductDTO otherProductDTO) {
        log.info("新增其他产品：{}", otherProductDTO);
        otherProductService.save(otherProductDTO);
        return Result.success();
    }

    @GetMapping("/page")
    @ApiOperation("其他产品分页查询")
    public Result<PageResult> page(OtherProductPageQueryDTO otherProductPageQueryDTO) {
        log.info("其他产品分页查询：{}", otherProductPageQueryDTO);
        PageResult pageResult = otherProductService.pageQuery(otherProductPageQueryDTO);
        return Result.success(pageResult);
    }
    @PutMapping("/{id}")
    @ApiOperation("修改其他产品")
    public Result update(@PathVariable Long id, @RequestBody OtherProductDTO otherProductDTO) {
        log.info("修改其他产品：{}", otherProductDTO);
        otherProductService.update(id, otherProductDTO);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除其他产品")
    public Result delete(@PathVariable Long id) {
        log.info("删除其他产品：{}", id);
        otherProductService.delete(id);
        return Result.success();
    }
}